home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / System Pulse ƒ / Source Code / Source / native jGNE.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.3 KB  |  145 lines

  1. #include <MacTypes.h>
  2.  
  3. #define OLDROUTINELOCATIONS        0
  4. #define OLDROUTINENAMES            0
  5. #define SystemSevenOrLater        1
  6.  
  7. #ifndef __FONTS__
  8. #    include <Fonts.h>
  9. #endif
  10.  
  11. #ifndef __DIALOGS__
  12. #    include <Dialogs.h>
  13. #endif
  14.  
  15. #ifndef __LOWMEM__
  16. #    include <LowMem.h>
  17. #endif
  18.  
  19.  
  20. static pascal OSErr InitMac (void)
  21. {
  22.     MaxApplZone ( );
  23.     InitGraf (&(qd.thePort));
  24.     InitFonts ( );
  25.     InitWindows ( );
  26.     InitMenus ( );
  27.     TEInit ( );
  28.     InitDialogs (nil);
  29.  
  30.     return noErr;
  31. }
  32.  
  33. static GetNextEventFilterUPP gGetNextEventFilterUPP;
  34. static Boolean gFilterDone;
  35.  
  36. enum { kNumStamps = 4 };
  37.  
  38. unsigned long timeStamps[kNumStamps];
  39. static int timeStampIndex = 0;
  40. static int lastTime = 0;
  41. static int numEvents = 0;
  42. Boolean gRefresh = 0;
  43.  
  44. static GetNextEventFilterUPP myFilterUPP = nil;
  45.  
  46. void doRefreshMenuBar()
  47. {    
  48.     gRefresh = 1;
  49. }
  50.  
  51. static unsigned long GetMSTicks()
  52. {
  53.     Duration tix;
  54.     unsigned long long time;
  55.     
  56.     Microseconds((UnsignedWide*) &time);
  57.     
  58.     tix = (time / 1000);
  59.     
  60.     return tix;
  61. }
  62.  
  63. static void myGetNextEventFilter (EventRecord *event, Boolean *result)
  64. {
  65.     // measure time between null events
  66.     //if (event->what != nullEvent)
  67.     {
  68.         numEvents++;
  69.     }
  70.     
  71.     if (gRefresh || event->what == mouseUp || event->what == keyUp)
  72.     {
  73.         gRefresh = 0;
  74.         DrawMenuBar();
  75.     }
  76.  
  77.     if (gGetNextEventFilterUPP)
  78.         CallGetNextEventFilterProc(gGetNextEventFilterUPP, event, result);
  79.  
  80. }
  81.  
  82.  
  83. int jGNECount()
  84. {
  85.     int i;
  86.     int count = numEvents; 
  87.     
  88.     numEvents = 0;
  89.     return  count;
  90. }
  91.  
  92. void InstalljGNE()
  93. {
  94.     int i;
  95.     myFilterUPP = NewGetNextEventFilterProc (myGetNextEventFilter);
  96.  
  97.     for (i = 0; i < kNumStamps; i++)
  98.     {
  99.         timeStamps[i] = 0;
  100.     }
  101.     
  102.     if (myFilterUPP)
  103.     {
  104.         gGetNextEventFilterUPP = LMGetGNEFilter ( );
  105.         LMSetGNEFilter (myFilterUPP);
  106.     }
  107. }
  108.  
  109. void RemovejGNE()
  110. {
  111.     if (LMGetGNEFilter ( ) == myFilterUPP)
  112.         LMSetGNEFilter (gGetNextEventFilterUPP);
  113.  
  114.     DisposeRoutineDescriptor (myFilterUPP);
  115. }
  116.  
  117. /*void main (void)
  118. {
  119.     if (!InitMac ( ))
  120.     {
  121.         GetNextEventFilterUPP myFilterUPP = NewGetNextEventFilterProc (myGetNextEventFilter);
  122.  
  123.         if (myFilterUPP)
  124.         {
  125.             gGetNextEventFilterUPP = LMGetGNEFilter ( );
  126.             LMSetGNEFilter (myFilterUPP);
  127.  
  128.             do
  129.             {
  130.                 EventRecord event;
  131.                 WaitNextEvent (everyEvent,&event,1,nil);
  132.             }
  133.             while (!gFilterDone);
  134.  
  135.             if (LMGetGNEFilter ( ) != myFilterUPP)
  136.                 DebugStr ("\pSomeone else has gotten into the jGNE filter chain!");
  137.             else
  138.                 LMSetGNEFilter (gGetNextEventFilterUPP);
  139.  
  140.             DisposeRoutineDescriptor (myFilterUPP);
  141.         }
  142.     }
  143. }
  144. */
  145.